from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
import os

class BaseHandler(webapp.RequestHandler):
	def generate_template(self, name, template_args):
		path = os.path.join('../templates', name)
		self.response.headers.add_header("P3P", 'policyref="/p3p.xml", CP="IDC DSP COR IVAi IVDi OUR TST"')
		return template.render(path, template_args)

	def write_response(self, data, **args):
		if 'content_type' in args:
			self.response.headers['Content-Type'] = args['content_type']
		self.response.out.write(data)	

	def render_template(self, name, template_args, **kwargs):
		self.write_response(self.generate_template(name, template_args), **kwargs)
